package com.atguigu.eduservice.service.impl;

import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.mapper.EduTeacherMapper;
import com.atguigu.eduservice.query.EduTeacherQuery;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author dayouzi
 * @since 2022-08-30
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {

    @Override
    public void pageQuery(Page<EduTeacher> pageParam, EduTeacherQuery eduTeacherQuery) {

        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("sort");

        if (eduTeacherQuery == null){
            //查询
            baseMapper.selectPage(pageParam, queryWrapper);
            return;
        }

        String name = eduTeacherQuery.getName();
        Integer level = eduTeacherQuery.getLevel();
        String begin = eduTeacherQuery.getBegin();
        String end = eduTeacherQuery.getEnd();

        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }

        if (!StringUtils.isEmpty(level)){
            queryWrapper.eq("level", level);
        }

        if (!StringUtils.isEmpty(begin)){
            queryWrapper.ge("gmt_create", begin);
        }

        if (!StringUtils.isEmpty(end)){
            queryWrapper.le("gmt_create", end);
        }

        //查询
        baseMapper.selectPage(pageParam, queryWrapper);

    }
}
